
clear all

use "./longbase.dta"
set type double
xtset ins year

forvalues j = 1/71 {

*local snum = `j'

merge 1:1 ins year using nominal, keepusing(sec`j')
rename sec`j' nom`j'
drop _merge

merge 1:1 ins year using real_dd, keepusing(sec`j')  // USE DD

rename sec`j' rea`j'
drop _merge

egen snom`j' = sum(nom`j'), by(year) 
gen sh`j' = nom`j'/snom`j' // share
gen pr`j' = nom`j'/rea`j'  // price index = nominal / real

gen lnsh`j' = ln(sh`j')
gen lnpr`j' = ln(pr`j')
}

gsort year ins
gen sec = ins

merge m:m sec year using tfp1
rename tfp tfp1
drop _merge
gen lntfp1 = ln(tfp1)
merge m:m sec year using tfp2
rename tfp tfp2
drop _merge
gen lntfp2 = ln(tfp2)
merge m:m sec year using tfp3
rename tfp tfp3
drop _merge
gen lntfp3 = ln(tfp3)

tabulate year, generate(t)

log using esiv.log //
xtivreg2 lnsh1 t1-t24 (lnpr1 = tfp1 tfp2), fe endog(lnpr1)
xtivreg2 lnsh2 t1-t24 (lnpr2 = l.tfp1 tfp2), fe endog(lnpr2)
xtivreg2 lnsh3 t1-t24 (lnpr3 = tfp1 l.tfp2), fe endog(lnpr3)
xtivreg2 lnsh4 t1-t24 (lnpr4 = tfp2 tfp1), fe endog(lnpr4)
xtivreg2 lnsh5 t1-t24 (lnpr5 = l.tfp2 tfp1), fe endog(lnpr5)
xtivreg2 lnsh6 t1-t24 (lnpr6 = tfp1 tfp2), fe endog(lnpr6) //*
*xtreg lnsh6 t1-t24 lnpr6, fe
xtivreg2 lnsh7 t1-t24 (lnpr7 = l.tfp1 tfp2), fe endog(lnpr7)
xtivreg2 lnsh8 t1-t24 (lnpr8 = l.tfp1 tfp2), fe endog(lnpr8)
xtivreg2 lnsh9 t1-t24 (lnpr9 = tfp1 tfp2), fe endog(lnpr9) //*
*xtreg lnsh9 t1-t24 lnpr9, fe
xtivreg2 lnsh10 t1-t24 (lnpr10 = tfp1 l.tfp2), fe endog(lnpr10) //***
xtreg lnsh10 t1-t24 lnpr10, fe
xtivreg2 lnsh11 t1-t24 (lnpr11 = l.tfp1 tfp2), fe endog(lnpr11) //*
*xtreg lnsh11 t1-t24 lnpr11, fe
xtivreg2 lnsh12 t1-t24 (lnpr12 = l.tfp1 tfp2), fe endog(lnpr12)
xtivreg2 lnsh13 t1-t24 (lnpr13 = l.tfp1 tfp2), fe endog(lnpr13)
xtivreg2 lnsh14 t1-t24 (lnpr14 = l.tfp1 tfp2), fe endog(lnpr14)
xtivreg2 lnsh15 t1-t24 (lnpr15 = l.tfp1 tfp2), fe endog(lnpr15)
xtivreg2 lnsh16 t1-t24 (lnpr16 = l.tfp1 tfp2), fe endog(lnpr16)
xtivreg2 lnsh17 t1-t24 (lnpr17 = l.tfp1 tfp2), fe endog(lnpr17)
xtivreg2 lnsh18 t1-t24 (lnpr18 = l.tfp1 tfp2), fe endog(lnpr18)
xtivreg2 lnsh19 t1-t24 (lnpr19 = l.tfp1 tfp2), fe endog(lnpr19)
xtivreg2 lnsh20 t1-t24 (lnpr20 = l.tfp1 tfp2), fe endog(lnpr20)
xtivreg2 lnsh21 t1-t24 (lnpr21 = l.tfp1 tfp2), fe endog(lnpr21) //*
*xtreg lnsh21 t1-t24 lnpr21, fe
xtivreg2 lnsh22 t1-t24 (lnpr22 = l.tfp1 tfp2), fe endog(lnpr22)
xtivreg2 lnsh23 t1-t24 (lnpr23 = tfp1 tfp2), fe endog(lnpr23)
xtivreg2 lnsh24 t1-t24 (lnpr24 = l.tfp1 tfp2), fe endog(lnpr24)
xtivreg2 lnsh25 t1-t24 (lnpr25 = l.tfp1 tfp2), fe endog(lnpr25)
xtivreg2 lnsh26 t1-t24 (lnpr26 = l.tfp1 tfp2), fe endog(lnpr26)
xtivreg2 lnsh27 t1-t24 (lnpr27 = l.tfp1 tfp2), fe endog(lnpr27)
xtivreg2 lnsh28 t1-t24 (lnpr28 = l.tfp1 tfp2), fe endog(lnpr28)
xtivreg2 lnsh29 t1-t24 (lnpr29 = l.tfp1 tfp2), fe endog(lnpr29)
xtivreg2 lnsh30 t1-t24 (lnpr30 = l.tfp1 tfp2), fe endog(lnpr30)
xtivreg2 lnsh31 t1-t24 (lnpr31 = l.tfp1 tfp2), fe endog(lnpr31)
xtivreg2 lnsh32 t1-t24 (lnpr32 = l.tfp1 tfp2), fe endog(lnpr32)
xtivreg2 lnsh33 t1-t24 (lnpr33 = l.tfp1 d.tfp2), fe endog(lnpr33)
xtivreg2 lnsh34 t1-t24 (lnpr34 = d.tfp1 d.tfp2), fe endog(lnpr34)
xtivreg2 lnsh35 t1-t24 (lnpr35 = l.tfp1 tfp2), fe endog(lnpr35)
xtivreg2 lnsh36 t1-t24 (lnpr36 = l.tfp1 tfp2), fe endog(lnpr36)
xtivreg2 lnsh37 t1-t24 (lnpr37 = l.tfp1 tfp2), fe endog(lnpr37) //*
*xtreg lnsh37 t1-t24 lnpr37, fe
xtivreg2 lnsh38 t1-t24 (lnpr38 = l.tfp2 tfp3), fe endog(lnpr38)
xtivreg2 lnsh39 t1-t24 (lnpr39 = l.tfp1 tfp2), fe endog(lnpr39)
xtivreg2 lnsh40 t1-t24 (lnpr40 = l.tfp1 tfp1), fe endog(lnpr40)
xtivreg2 lnsh41 t1-t24 (lnpr41 = tfp1 l.tfp2), fe endog(lnpr41) //*
*xtreg lnsh41 t1-t24 lnpr41, fe
xtivreg2 lnsh42 t1-t24 (lnpr42 = tfp2 l.tfp3), fe endog(lnpr42)
xtivreg2 lnsh43 t1-t24 (lnpr43 = l.tfp1 tfp2), fe endog(lnpr43)
xtivreg2 lnsh44 t1-t24 (lnpr44 = l.tfp1 d.tfp2), fe endog(lnpr44)
xtivreg2 lnsh45 t1-t24 (lnpr45 = l.tfp2 l.tfp3), fe endog(lnpr45)
xtivreg2 lnsh46 t1-t24 (lnpr46 = l.tfp1 tfp2), fe endog(lnpr46)
xtivreg2 lnsh47 t1-t24 (lnpr47 = l.tfp1 tfp2), fe endog(lnpr47)
xtivreg2 lnsh48 t1-t24 (lnpr48 = tfp1 l.lntfp2), fe endog(lnpr48) //*
*xtreg lnsh48 t1-t24 lnpr48, fe
xtivreg2 lnsh49 t1-t24 (lnpr49 = l.tfp1 tfp2), fe endog(lnpr49)
xtivreg2 lnsh50 t1-t24 (lnpr50 = l.tfp1 tfp2), fe endog(lnpr50)
xtivreg2 lnsh51 t1-t24 (lnpr51 = l.tfp1 tfp1), fe endog(lnpr51)
xtivreg2 lnsh52 t1-t24 (lnpr52 = l.tfp1 tfp3), fe endog(lnpr52)
xtivreg2 lnsh53 t1-t24 (lnpr53 = l.tfp1 tfp2), fe endog(lnpr53)
xtivreg2 lnsh54 t1-t24 (lnpr54 = l.tfp1 tfp1), fe endog(lnpr54)
xtivreg2 lnsh55 t1-t24 (lnpr55 = l.tfp1 l.tfp2), fe endog(lnpr55) //*
*xtreg lnsh55 t1-t24 lnpr55, fe
xtivreg2 lnsh56 t1-t24 (lnpr56 = l.tfp1 tfp2), fe endog(lnpr56) //*
*xtreg lnsh56 t1-t24 lnpr56, fe
xtivreg2 lnsh57 t1-t24 (lnpr57 = l.tfp1 tfp1), fe endog(lnpr57)
xtivreg2 lnsh58 t1-t24 (lnpr58 = l.tfp1 tfp1), fe endog(lnpr58)
xtivreg2 lnsh59 t1-t24 (lnpr59 = l.tfp1 tfp2), fe endog(lnpr59)
xtivreg2 lnsh60 t1-t24 (lnpr60 = tfp1 l.tfp2), fe endog(lnpr60)
xtivreg2 lnsh61 t1-t24 (lnpr61 = tfp1 l.tfp2), fe endog(lnpr61)
xtivreg2 lnsh62 t1-t24 (lnpr62 = tfp1 l.tfp2), fe endog(lnpr62) //*
*xtreg lnsh62 t1-t24 lnpr62, fe
xtivreg2 lnsh63 t1-t24 (lnpr63 = tfp1 l.tfp2), fe endog(lnpr63) //*
*xtreg lnsh63 t1-t24 lnpr63, fe
xtivreg2 lnsh64 t1-t24 (lnpr64 = l.tfp1 tfp2), fe endog(lnpr64)  //*
*xtreg lnsh64 t1-t24 lnpr64, fe
xtivreg2 lnsh65 t1-t24 (lnpr65 = l.tfp2 tfp1), fe endog(lnpr65) //*
*xtreg lnsh65 t1-t24 lnpr65, fe
xtivreg2 lnsh66 t1-t24 (lnpr66 = l.tfp1 tfp1), fe endog(lnpr66)
xtivreg2 lnsh67 t1-t24 (lnpr67 = l.tfp1 tfp1), fe endog(lnpr67)
xtivreg2 lnsh68 t1-t24 (lnpr68 = f.tfp1 tfp2), fe endog(lnpr68)
xtivreg2 lnsh69 t1-t24 (lnpr69 = l.tfp1 tfp3), fe endog(lnpr69)
xtivreg2 lnsh70 t1-t24 (lnpr70 = l.tfp1 tfp1), fe endog(lnpr70)
xtivreg2 lnsh71 t1-t24 (lnpr71 = l.tfp1 tfp1), fe endog(lnpr71) //*
*xtreg lnsh71 t1-t24 lnpr71, fe
log close //

log using eslr.log
forvalues j = 1/71{
xtreg lnsh`j' t1-t24 lnpr`j', fe
}
log close


/*
****************************************************
* MAC UNIX
* grep "lnpr" es.log | grep "|" > es.out
****************************************************
*xtivreg2 lnsh1 t1-t24 (lnpr1 = tfp f.lntfp), fe endog(lnpr1)
